package com.simon.mengkou.wxapi;






import com.ouertech.android.agm.lib.base.utils.UtilLog;
import com.simon.mengkou.system.constant.CstOuer;
import com.simon.mengkou.system.global.OuerDispatcher;
import com.simon.mengkou.wxpay.Util;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{

	
    private IWXAPI api;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    	api = WXAPIFactory.createWXAPI(this, CstOuer.WECHAT.WECHAT_APP_ID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {

	}

	@Override
	public void onResp(BaseResp resp) {
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			if(resp.errCode == BaseResp.ErrCode.ERR_OK) {//微信支付成功
				OuerDispatcher.sendWxPayResultBroadcast(this, BaseResp.ErrCode.ERR_OK);
			} else {//微信支付失败
				OuerDispatcher.sendWxPayResultBroadcast(this, BaseResp.ErrCode.ERR_SENT_FAILED);
			}

			finish();
		}
	}
}